package leetcode.code0372;

import leetcode.helper.MaxDebug;

public class Solution extends S372 {

	private int Mod = 1337;

	@Override
	public int superPow(int a, int[] b) {
		if (a == 1)
			return 1;
		long basic = a;
		long ans = 1;
		for (int i = b.length - 1; i >= 0; i--) {
			ans = ans * pow(basic, b[i]) % Mod;
			basic = this.pow(basic, 10) % Mod;
		}
		return (int) ans;
	}

	private long pow(long basic, int n) {
		if (n == 0) {
			return 1;
		}
		long b = pow(basic, n >> 1) % Mod;
		return (n & 1) == 0 ? b * b : b * b * basic;
	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug5();
		so.debug4();
		MaxDebug.debug14(so);

	}

}
